<h2><?php echo henc(_('DB Change Scripts')); ?></h2>

<?php if(isset($scriptContents)) : ?>
<h3><?php echo sprintf(_('View DB Change Script <em>%s</em>'),$scriptFile); ?></h3>
<div style="border:1px solid navy;margin:5px;padding:5px;width:95%;height:200px;overflow:auto">
<?php echo $scriptContents; ?>
</div>
<p>
<?php echo CHtml::link(_('Run Script'),array('run','script'=>$scriptFile,array('confirm'=>sprintf(_('Really run script %s?'),$scriptFile)))); ?>
</p>
<?php endif; ?>

<?php if(isset($logContents)) : ?>
<h3><?php echo sprintf(_('View Log for DB Change Script <em>%s</em>'),$logFile); ?></h3>
<div style="border:1px solid navy;margin:5px;padding:5px;width:95%;height:200px;overflow:auto">
<?php echo $logContents; ?>
</div>
<?php endif; ?>

<?php if(isset($queries)) : ?>
<h3><?php echo sprintf(_('Results for Script <em>%s</em>'),$_GET['script']); ?></h3>
<ul>
<?php foreach($queries as $n=>$query) :  ?>
<li><?php echo sprintf(_('Query %d: %s'),$n+1,substr($query,0,60).'...'); ?>
<?php if(isset($errors[$n+1])) : ?>
<li><?php echo $errors[$n+1]; ?>
<?php endif; ?>
<?php if(isset($results[$n+1])) : ?>
<li><?php echo sprintf(_('Affected Rows: %d'),$results[$n+1]); ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>

<table class="dataGrid">
    <thead>
        <tr>
            <th><?php echo henc(_('File name')); ?></th>    
            <th><?php echo henc(_('File Date')); ?></th>    
            <th><?php echo henc(_('Last Run Date')); ?></th>    
            <th></th>
        </tr>
    </thead>
    <tbody>
        <?php $c=0; foreach($files as $file) : ?>
        <tr class="<?php echo $c%2 ? 'even' : 'odd' ?>">
            <td><?php echo CHtml::encode($file['file']); ?></td>
            <td class="centered"><?php echo Yii::app()->dateFormatter->formatDateTime($file['filectime'],'medium','medium'); ?></td>
            <td class="centered">
                <?php if($file['log']!='') : ?>
                <?php echo CHtml::link(Yii::app()->dateFormatter->formatDateTime($file['log'],'medium','medium'),array('viewLog','script'=>$file['file']),array('title'=>sprintf(_('View Log File for DB Change Script %s'),$file['file']))); ?>
                <?php else : ?>
                &ndash;
                <?php endif; ?>
            </td>
            <td class="centered">
                <?php echo CHtml::link(_('View'),array('view','script'=>$file['file']),array('title'=>sprintf(_('View DB Change Script %s'),$file['file']))); ?> |
                <?php echo CHtml::link(_('Run'),array('run','script'=>$file['file']),array('confirm'=>sprintf(_('Really run script %s?'),$file['file']))); ?>
            </td>
        </tr>
        <?php $c++; endforeach; ?>
    <tbody>
</table>
